jQuery(document).ready(function($) {

	// Filter

  var filterType = $("ul#filter li a");
  var filterItem = $(".filter-handle");

  filterType.click(function(e) {
    var type = $(this).attr("class");
    if (type == "all") {
      filterItem.find('section').css('transform', 'scale(1,1)');
    }else{
      filterItem.find("."+type).css('display', 'block');
      filterItem.find("."+type).css('transform', 'scale(1,1)');
      var notItem = filterItem.find("section:not(."+type+")");
      filterItem.append(notItem);
      notItem.css('transform', 'scale(0,0)');
    }
    e.preventDefault();
  });

  // FIX FLOAT MENU

    var top = 100;
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        $('aside section').addClass('fixed');
        $('aside section:last-child').css("top",100);
      } else {
        // otherwise remove it
        $('aside section').removeClass('fixed');
      }
    });

    //  FIX height

    // JQUERY TABS
    var ulNav = $("#description .decLeft ul#nav");
    var liNav = $("#description .decLeft ul#nav li");
    var wrape = $("#description .decLeft");
    liNav.click(function(e) {

      liNav.removeClass("active");
      $(this).addClass("active");
      var liAttr = $(this).find("a").attr("class");
      wrape.find(".tabs-active").hide();
      wrape.find("div#"+liAttr).addClass("tabs-active");
      wrape.find("div#"+liAttr).show();

      //
      e.preventDefault();
    });

  // CLICK FUNCTION
  //  MENU LOGATION
  var locaMenu = $("aside section:last-child nav ul li:first-child");
  var locaShow = $("aside section:last-child nav ul li:first-child div.choose_city");
  locaMenu.click(function(e) {
    var OnlocaShow = $("aside section:last-child nav ul li:first-child").find(".OnlocaShow");
    if (OnlocaShow.html() == null) {
      locaShow.css('display', 'block');
      locaShow.addClass("OnlocaShow")
    }else{
      locaShow.css('display', 'none');
      locaShow.removeClass("OnlocaShow")
    };
    e.preventDefault();
  });


  //
  var sub = $("li a.jSubs");
  sub.click(function(e) {

    $(".jSubc").slideToggle();

    e.preventDefault();
  });
  var localClose = $(".jSubc .close");
  localClose.click(function(e) {
    $(".jSubc").slideToggle();
  });
  // LOGIN

  var login = $("header > nav ul#top-menu li.login a.jLogin");
  var loginLi = $("header > nav ul#top-menu li.login");
  var loginOption = $("header > nav ul#top-menu li.login div.login-option");
  var loginEm = $("header > nav ul#top-menu li.login div.login-option .arrow em");
  loginEm.click(function(e) {
      loginLi.css('height', 30);
      loginOption.css('display', 'none');
      loginOption.removeClass("onLogin");
    e.preventDefault();
  });
  //  END CLOSE
  login.click(function(e) {
    // loginOption.css('display', 'block');
    // loginOption.addClass("onLogin");
    var onLogin = $("header > nav ul#top-menu li.login").find(".onLogin");
    if (onLogin.html()==null) {
      loginLi.css('height', 37);
      loginOption.css('display', 'block');
      loginOption.addClass("onLogin");
    }else{
      loginLi.css('height', 30);
      loginOption.css('display', 'none');
      loginOption.removeClass("onLogin");
    };
    e.preventDefault();
  });

  // USER
  var userLi = $("header > nav ul#top-menu li.user");
  var userPanel = $("header > nav ul#top-menu li.user .userPanel");

  userLi.click(function(e) {
    var onUser = userLi.find(".onUser");
    if (onUser.html() == null) {
      userLi.css("height",37);
      userPanel.css('display', 'block');
      userPanel.addClass("onUser");
    }else{
      userLi.css("height",30);
      userPanel.css('display', 'none');
      userPanel.removeClass("onUser");
    };



    e.preventDefault();
  });

  // Up ANd DOWn

  var secHover = $("article section:nth-child(2) #grids-3 > section");
  var secHoverP = $("article section:nth-child(2) #grids-3 > section article p");
  // secHoverP.css('margin-bottom', 100);

  // CHECk OUT STEp 1
  var checkWrap = $("#shipway");
  var checkSelect = $("#shipway .selected");
  var wayGo = $("#shipway .selected .select-way");

  checkWrap.find(".onGo").find(".select-way").css('display', 'block');

  checkSelect.click(function(e) {

    $(".onGo").find(".select-way").hide();
    $(".onGo").find(".way").css({
      'background':'#59c4cc url(images/option-checked.jpg) 120px center no-repeat',
      'background-position-x':120
    });

    checkWrap.find(".onGo").removeClass("onGo");

    $(this).addClass("onGo");
    checkWrap.find(".onGo").find(".select-way").show();
    // CSS
    $(this).find('.way').css({
      'background':'#59c4cc url(images/option-check.jpg) 120px center no-repeat',
      'background-position-x':120
    });
    // HANDLE
    e.preventDefault();
  });
  // GIFt CHECK
  $('#shipway .select-way form input[type="text"]').attr("disabled","disabled")
  var giftCheck = $(".giftCheck");
  giftCheck.toggle(
    function(){
      $(this).find('i').css({
        background: 'url(images/gift_check_btn.png) left bottom no-repeat',
      })
      $('#shipway .select-way form input[type="text"]').removeAttr("disabled","disabled");
    },
    function(){
      $(this).find('i').css({
        background: 'url(images/gift_check_btn.png) left top no-repeat',
      })
      $('#shipway .select-way form input[type="text"]').attr("disabled","disabled")
    }
  )

  // FAQs
  var FaqsLi = $("article section:nth-child(2) #gridsInfo ul.fqa li");
  FaqsLi.click(function(e) {
    $('.FaqActive').find('p').css('display','none');
    FaqsLi.removeClass('FaqActive');
    $(this).addClass("FaqActive");
    $(this).find('p').css("display","block");
    e.preventDefault();
  });

});
